<template>
  <div class="app-container">
    <el-radio-group v-model="queryParams" @change="histTypeUpdate">
      <el-radio-button label="1" >昨天</el-radio-button>
      <el-radio-button label="7">最近7天</el-radio-button>
      <el-radio-button label="30">最近一月</el-radio-button>
    </el-radio-group>
    <el-form :model="paramsForm" ref="timeForm" :inline="true" label-width="75px" style="margin-left: 300px;margin-top: -35px;">
      <!-- <el-form-item label="开始时间" prop="beginTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="paramsForm.startTime"
          type="date"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="paramsForm.endTime"
          type="date"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择结束时间">
        </el-date-picker>
      </el-form-item> -->
      <el-form-item>
        <el-date-picker
          v-model="dateParams"
          type="daterange"
          value-format="yyyy-MM-dd HH:mm:ss"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 图表 -->
    <div class="chart-wrapper">
      <mutl-chart :chartdata="machineReportData" :title="title" />
    </div>
    <!-- 表格 -->
    <el-table  v-loading="loading" :data="statisticsList">
       <el-table-column label="序号" align="center" prop="id"    />
       <el-table-column label="订单编号" width="200" align="center" prop="outTradeNo"  />
       <el-table-column label="mac地址" width="200" align="center" prop="macAddress" />
       <el-table-column label="sn" width="200" align="center" prop="sn" />
      <el-table-column label="状态" align="center" prop="status" >
        <template slot-scope="scope">
          <span v-if="scope.row.status == 0">待支付</span>
          <span v-if="scope.row.status === '1'">已支付</span>
          <span v-if="scope.row.status === '2'">已完成</span>
          <span v-if="scope.row.status === '3'">已退款</span>
        </template>
      </el-table-column>
      <el-table-column label="价格" align="center" prop="price" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
    </el-table>
     <pagination
      v-show="total>0"
      :total="total"
      :page.sync="newPage.pageNum"
      :limit.sync="newPage.pageSize"
      @pagination="getStatisticsListInfo"
    />
  </div>
</template>
<script>
import { getStatisticsList } from "@/api/system/statistics";
import MutlChart from "./MutlChart";

export default {
  name: "oederStatistics",
  components: {
    MutlChart
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 分组管理表格数据
      groupList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,

      statisticsList: [],

      machineReportData: {
        xData: [],
        statisticsYData: {}
      },
      title: "最近7天",
      // 查询参数
      queryParams: "7",
      dateParams: "", //日期数组
      newPage:{
        pageNum: 1,
        pageSize: 10,
      },
      paramsForm: {
        yesterDay: null,
        sevenDay: null,
        month: null,
        startTime: null,
        endTime: null
      },
      // 表单参数
      form: {}
    };
  },
  created() {
    this.getStatisticsListInfo();
  },
  methods: {
     /** 搜索按钮操作 */
    handleQuery() {
      if(this.dateParams == ""){
        this.queryParams = "7";        
        this.paramsForm = {
            yesterDay: null,
            sevenDay: "7",
            month: null,
            startTime: null,
            endTime: null
        };
      }else{
        this.queryParams = "";
        this.paramsForm = {
            yesterDay: null,
            sevenDay: null,
            month: null,
            startTime: this.dateParams[0],
            endTime: this.dateParams[1]
        };
        this.title=this.dateParams[0].substr(0,10)+"至"+this.dateParams[1].substr(0,10);
      }
      console.log(this.dateParams);
      this.getStatisticsListInfo();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("timeForm");
      this.handleQuery();
    },
    histTypeUpdate: function(value) {
      if(value === "1") {
        this.title = "昨天";
        this.paramsForm = {
          yesterDay: "1",
          sevenDay: null,
          month: null,
          startTime: null,
          endTime: null
        };
      }else if(value === "7"){
        this.title = "最近7天";
        this.paramsForm = {
          yesterDay: null,
          sevenDay: "7",
          month: null,
          startTime: null,
          endTime: null
        };
      }else if(value === "30"){
        this.title = "最近一月";
        this.paramsForm = {
          yesterDay: null,
          sevenDay: null,
          month: "30",
          startTime: null,
          endTime: null
        };
      }
       getStatisticsList(this.paramsForm).then(response => {
        this.statisticsList = response.data.list;
        this.total = response.data.list.length
        this.machineReportData= {
          xData: response.data.xData,
          statisticsYData: response.data.statisticsYData
        };
      });
    },
    getStatisticsListInfo() {
       getStatisticsList(this.paramsForm).then(response => {
        this.statisticsList = response.data.list;
        this.total = response.data.list.length
        this.machineReportData= {
          xData: response.data.xData,
          statisticsYData: response.data.statisticsYData
        };
        this.loading = false;
      });
    }
  }
};

</script>